<template>
	<view class="detail">
		<view class="order-status bg-theme">{{detail.order_status_text}}</view>
		<view class="address">
			<view class="icon">
				<view class="iconfont icon-dizhi-01"></view>
			</view>
			<view class="info">
					<view class="top">
						<view>{{detail.address.recipients}}</view>
						<view>{{detail.address.mobile}}</view>
					</view>
					<view class="content">{{detail.address.province}} {{detail.address.city}} {{detail.address.area}} {{detail.address.address}}</view>	
			</view>
			
		</view>
		
		<view class="orders">
			<view class="goods">
				<order-goods :show-apply="(detail.pay_status == 1 && detail.order_status != 0) ? true : false" @toDetail="toGoodsDetail(goods)" :goods="goods" v-for="(goods, goodsIndex) in detail.goods" :key="goodsIndex"></order-goods>
			</view>
				
			<view class="count">
				<view class="number">共{{detail.goods_number}}件商品</view>
				<view class="price">合计：￥{{detail.order_amount}}</view>
			</view>
			
			<view class="footer" v-if="detail.order_status > 0 && detail.order_status <= 4">
				<!-- 关闭或完成可删除订单 -->
				<view @tap="del(detail)" class="btn" v-if="detail.order_status == 0 || detail.order_status == 4">删除订单</view>
				
				<!-- 未付款可取消订单 -->
				<view @tap="cancel(detail)" class="btn" v-if="detail.order_status == 1">取消订单</view>
				
				<view @tap="pay(detail)" class="btn" v-if="detail.order_status == 1">付款</view>
				
				<!-- 等待卖家发货 -->
				<view @tap="remind(detail)" class="btn" v-if="detail.order_status == 2">提醒发货</view>
				
				<!-- 卖家已发货 -->
				<view @tap="shipping(detail)" class="btn" v-if="detail.order_status == 3 || detail.order_status == 4">查看物流</view>
				
				<view @tap="signOrder(detail)" class="btn danger" v-if="detail.order_status == 3">确认收货</view>
				
				
				<!-- 订单完成 -->
				<view @tap="comment(detail)" class="btn danger" v-if="detail.order_status == 4">评价订单</view>
				
			</view>
			
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<view>商品总价</view>
						<view class="text-gray">{{detail.goods_amount}}</view>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<view>积分抵扣</view>
						<view class="text-gray">{{detail.integral_money}}</view>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<view>优惠券抵扣</view>
						<view class="text-gray">{{detail.coupon_price}}</view>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<view>运费</view>
						<view class="text-gray">{{detail.freight}}</view>
					</view>
				</view>
				
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<view>订单总价</view>
						<view class="text-danger">{{detail.order_amount}}</view>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<view>备注</view>
						<view class="text-gray">{{detail.message}}</view>
					</view>
				</view>
						
			</view>
		</view>
		
		<view class="info text-gray">
			<view>订单类型：<text class="text-danger">{{detail.order_prom_type_text}}</text></view>
			<view class="data-box text-danger" id="dateShow1" v-if="detail.order_prom_type == 2">
				<b>
					剩余使用时间：
					<span class="date-tiem d">00</span>天
					<span class="date-tiem h">00</span>时
					<span class="date-tiem m">00</span>分
					<span class="date-s s">00</span>秒
				</b>
			</view>
			<view v-if="detail.order_prom_type == 1">发货数量：{{detail.delivery_task.delivery_number}}/{{detail.delivery_task.need_number}}</view>
			<view>订单号:{{detail.order_no}}</view>
			<view>订单总价：{{detail.order_amount}}</view>
			<view>创建时间：{{detail.create_time}}</view>
			<view v-if="detail.pay_time">付款时间：{{detail.pay_time}}</view>
			<view v-if="detail.shipping_time">发货时间：{{detail.shipping_time}}</view>
			<view v-if="detail.confirm_time">成交时间：{{detail.confirm_time}}</view>
		</view>
	</view>
</template>

<script>
	import Request from '../../common/request.js';
	import orderGoods from '../../components/order-goods.vue';
	
	export default {
		components: {
			orderGoods
		},
		data() {
			return {
				orderId: '',
				detail: {}
			};
		},
		onLoad(options) {
			this.orderId = options.order_id;
			this.getOrder();
		},
		methods: {
			getOrder(){
				var that = this;
				Request.send({
					url: 'order/detail',
					data: {
						order_id: that.orderId
					},
					sCallback: function(res) {
						that.detail = res.data;
					}
				})
				
			},
			//删除订单
			del: function(item){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认删除该订单吗？',
					success(e) {
						if(e.confirm == 1) {
							Request.send({
								url: 'order/delOrder',
								data: {id: item.id},
								sCallback: function(res) {
									that.detail.order_status = 0;
								}
							})
						}
					}
				});
			},
			//取消订单
			cancel: function(item){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认取消该订单吗？',
					success(e) {
						if(e.confirm == 1) {
							Request.send({
								url: 'order/cancelOrder',
								data: {id: item.id},
								sCallback: function(res) {
									that.detail.order_status = 0;
								}
							})
						}
					}
				});
				
			},
			//提醒发货
			remind: function(item){
				var that = this;
				Request.send({
					url: 'order/orderRemind',
					data: {order_id: item.id},
					sCallback: function(res) {
						uni.showToast({
							title:res.msg
						})
					}
				});
			},
			//查看物流
			shipping: function(item){
				uni.navigateTo({
					url: '/pages/order/shipping?code='+item.shipping_code+'&no='+item.shipping_no+'&name='+item.shipping_name
				})
				
			},
			//确认收货
			signOrder: function(item){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认签收该订单吗？',
					success(e) {
						if(e.confirm == 1) {
							Request.send({
								url: 'order/signOrder',
								data: {order_id: item.id},
								sCallback: function(res) {
									that.detail.order_status = 4;
								}
							})
						}
					}
				});
				
			},
			//评价订单
			comment: function(item) {
				uni.navigateTo({
					url: '/pages/order/comment?order_id='+item.id
				})
			},
			//支付订单
			pay: function(item) {
				uni.navigateTo({
					url: '/pages/order/payorder?type=order&id='+item.id
				})
			},
			//商品详情
			toGoodsDetail: function(goods) {
				uni.navigateTo({
					url: '/pages/goods/detail?id='+goods.goods_id
				})
			}
		}
	}
</script>

<style>
	.detail{
		font-size: 28upx;
		border-top: 1upx solid #eee;
	}
	
	.detail .order-status{
		
		height: 100upx;
		display: flex;
		align-items: center;
		padding: 0 40upx;
		font-size: 32upx;
		font-weight: 600;
		color: #fff
	}
	/* 地址样式开始 */
		.detail .address{
			padding: 30upx 20upx;
			border-bottom: 1upx solid #eee;
			background: #fff;
			display: flex;
			width: 100%;
			font-size: 28upx;
			align-items: center;
			box-sizing: border-box;
		}

		.detail .address .icon{
			width: 80upx;
			color: #666;
		}
		.detail .address .icon .iconfont{
			font-size: 40upx;
		}
		.detail .address .info{
			flex: 1;
			padding-right: 10upx;
			color: #666
		}
		.detail .address .info .top{
			display: flex;
			justify-content: space-between;
		}
		

		.detail .address .info .tips{
			display: flex;
			align-items: center;
		}

		.detail .address .info .tips navigator{
			background: #FD0136;
			color: #fff;
			margin-left: 20upx;
			padding: 8upx 20upx;
			border-radius: 10upx;
			font-size: 24upx;
		}
	/* 地址样式结束 */
	
	.detail>.info {
		margin-top: 20upx;
		line-height: 50upx;
		background: #fff;
		padding: 20upx;
	}
	.orders{
		background: #fff;
	}
	
	.orders .count{
		display: flex;
		justify-content: flex-end;
		height: 80upx;
		align-items: center;
		padding: 0 20upx;
		color: #666;
		border-bottom: 1upx solid #eee;
	}
	
	.orders .count .price{
		margin-left: 40upx;
	}
	
	.orders .footer {
		height: 100upx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: 0 20upx;
	}
	
	.orders .footer .btn{
		height: 60upx;
		border: 1upx solid #999;
		display: flex;
		align-items: center;
		font-size: 24upx;
		padding: 0 20upx;
		border-radius: 10upx;
		margin-left: 20upx;
	}
	
	.orders .footer .btn.danger{
		color: #E60012;
		border-color: #E60012;
	}
</style>
